﻿using System;
using System.Data;
using System.Configuration;
using System.Collections;
using System.Web;
using System.Web.Security;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Web.UI.WebControls.WebParts;
using System.Web.UI.HtmlControls;

public partial class Comod_LibraryOut : ATPages
{
    Function f = new Function();
    ZSql zs = new ZSql();
    ZSql info = new ZSql();//添加修改
    protected void Page_Load(object sender, EventArgs e)
    {
        if (!IsPostBack)
        {
            txttdate.Text = DateTime.Now.ToShortDateString();
            Hidid.Value = Request.QueryString["Id"].Trim();
            HidReturnId.Value = Request.QueryString["ReturnId"].Trim();
            lblName.Text = Server.UrlDecode(Request.Cookies["user"].Values["realname"]);
            lblPath.Text = f.getModuleidAdd(Request.QueryString["moduid"]);
            HidGoUrl.Value = Request.UrlReferrer.ToString();
            initData();

        }
    }

    protected void btnAdd_Click(object sender, EventArgs e)
    {   
        string isDel = Request.Form["isDel"];
        string sql = "";
        zs.Open("update CS_Sales set isDel=" + isDel + " where SalesId="+Hidid.Value);
        zs.Close();
        // 退货信息表
        if (!string.IsNullOrEmpty(HidReturnId.Value))
            sql = "select top 1  * from CS_Return where ReturnId=" + HidReturnId.Value.Trim();
        else 
            sql = "select top 1  * from CS_Return ";

        info.Open(sql);
        info.NextRow();
        if (string.IsNullOrEmpty(HidReturnId.Value))
        {
            info.NewRow();
        }
            info["SalesId"] = Hidid.Value.Trim();
            info["ReturnMan"] = lblName.Text;
            info["ReturnContent"] = txtContent.Text;
            info["returnDate"] = DateTime.Now.ToString();
        info.Update();
        info.Close();
        Response.Write("<script>alert('操作已成功，请返回！');</script>");//返回页面
        Response.Write("<script>window.location='" + HidGoUrl.Value + "';</script>");//返回页面
    }

    private void initData()
    {
        string sql = "select * from (select a.*,(select top 1 realname from UserInfo where a.userid=userid) as realname, (select GuestName from CS_Guest where a.guestid=guestid) as GuestName,(select StaffName from CS_Staff where StaffId=a.Saleman) as  StaffName,(select deptName from department where a.deptid=deptid) as deptName  from CS_Sales a )TblSales where SalesId="+Request.QueryString["Id"].Trim()+"  order by SalesId desc";
        zs.Open(sql);
            SalesCode.Text = zs.m_table.Rows[0]["SalesCode"].ToString();//订单编号
            GuestName.Text = zs.m_table.Rows[0]["GuestName"].ToString();//客户名称
            comodBarcode.Text = zs.m_table.Rows[0]["comodBarcode"].ToString();//型号编号
            practical.Text = zs.m_table.Rows[0]["practical"].ToString();//成交价
            Totalpractical.Text = zs.m_table.Rows[0]["Totalpractical"].ToString();//总金额
            c_date.Text = zs.m_table.Rows[0]["c_date"].ToString();//开单日期
            brand.Text = zs.m_table.Rows[0]["brand"].ToString();//品牌
            comodName.Text = zs.m_table.Rows[0]["comodName"].ToString();//商品名称
            modul.Text = zs.m_table.Rows[0]["modul"].ToString();//型号
            number.Text = zs.m_table.Rows[0]["number"].ToString();//数量
            StaffName.Text = zs.m_table.Rows[0]["StaffName"].ToString();//销售员
            realname.Text = zs.m_table.Rows[0]["realname"].ToString();//开票人
        zs.Close();
        if (!string.IsNullOrEmpty(Request.QueryString["ReturnId"])) 
        {
            sql = "select top 1 * from CS_Return where ReturnId=" + Request.QueryString["ReturnId"].Trim() + " order by ReturnId desc";
            zs.Open(sql);
                txtContent.Text = zs.m_table.Rows[0]["ReturnContent"].ToString();
                lblName.Text = zs.m_table.Rows[0]["ReturnMan"].ToString();
            zs.Close();
        }

    }

}
